package com.juku2024.juku.adapter

import com.chad.library.adapter.base.BaseDelegateMultiAdapter
import com.chad.library.adapter.base.delegate.BaseMultiTypeDelegate
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.model.EpisodesResponse
import com.juku2024.juku.model.VideoSourceModel
import com.juku2024.juku.tools.Constants
import com.wanban.download.model.Status

class DownloadListAdapter(videoPlayList: ArrayList<EpisodesResponse>) :
    BaseDelegateMultiAdapter<EpisodesResponse, BaseViewHolder>(videoPlayList){

    var isAlbumType = true

    init {
        setMultiTypeDelegate(object : BaseMultiTypeDelegate<EpisodesResponse>() {
            override fun getItemType(data: List<EpisodesResponse>, position: Int): Int {
                return if (isAlbumType) {
                    0
                } else {
                    1
                }
            }
        })

        getMultiTypeDelegate()?.apply {
            addItemType(0, R.layout.item_download_album)

            addItemType(1, R.layout.item_download_zy)
        }
    }


    override fun convert(holder: BaseViewHolder, item: EpisodesResponse) {
        val title = if (isAlbumType) {
            (holder.layoutPosition + 1).toString()
        } else {
            item.title
        }
        holder.setText(R.id.tvEpisode, title)

        val resId = when (item.status) {
            Status.PREPARE -> R.drawable.ic_dl_idle
            Status.STOP -> R.drawable.ic_dl_idle
            Status.ERROR -> R.drawable.ic_dl_idle
            Status.START -> R.drawable.ic_dl_downing
            Status.DOWNLOADING -> R.drawable.ic_dl_downing
            Status.SUCCESS -> R.drawable.ic_dl_finish
                else -> 0
            }

        holder.setBackgroundResource(R.id.downloadStatus, resId)
    }
}